<?php 
class AdVehicle extends Ad
{
	public $AdVehicleId;
	public $MaintenanceDoc;
	public $AirCondition;
	public $AditionalHydra;
	public $CeMarked;
	public $ConformityDeclaration;
	public $YearReg;
	public $AutoTrans;
	public $TrailerBreak;
	public $LoadCapacityVolume;
	public $LoadCapacityWeight;
	public $RegistrationNo;
	public $EuApproved;
	public $EuApprovedDate;
	public $CabinType;
	public $SuspensionFront;
	public $SuspensionRear;
	public $Wheelbase;
	public $ShaftType;
	public $TailLift;
	public $InsideLength;
	public $InsideWidth;
	public $ClutchlessTurningGear;
	public $SpeedGear;
	public $SpringCottage;
	public $SuspFrontAxle;
	public $IsTracked;
	
	public function getAdVehicleId() { return intval($this->AdVehicleId); }
	public function getMaintenanceDoc() { return intval($this->MaintenanceDoc); }
	public function getAirCondition() { return intval($this->AirCondition); }
	public function getAditionalHydra() { return intval($this->AditionalHydra); }
	public function getCeMarked() { return intval($this->CeMarked); }
	public function getConformityDeclaration() { return intval($this->ConformityDeclaration); }
	public function getAutoTrans() { return intval($this->AutoTrans); }
	public function getTrailerBreak() { return intval($this->TrailerBreak); }
	public function getLoadCapacityVolume() { return intval($this->LoadCapacityVolume); }
	public function getLoadCapacityWeight() { return intval($this->LoadCapacityWeight); }
	public function getEuApproved() { return intval($this->EuApproved); }
	public function getWheelbase() { return intval($this->Wheelbase); }
	public function getTailLift() { return intval($this->TailLift); }
	public function getInsideLength() { return intval($this->InsideLength); }
	public function getInsideWidth() { return intval($this->InsideWidth); }
	public function getClutchlessTurningGear() { return intval($this->ClutchlessTurningGear); }
	public function getSpeedGear() { return intval($this->SpeedGear); }
	public function getSpringCottage() { return intval($this->SpringCottage); }
	public function getSuspFrontAxle() { return intval($this->SuspFrontAxle); }
	public function getIsTracked() { return intval($this->IsTracked); }
	
	public function getYearReg($format = 'd.m.Y') 
	{ 
		if(self::formatDate($this->YearReg, $format) != date($format, 0))
		{ return self::formatDate($this->YearReg, $format); }
		else
		{ return ''; }
	}
	public function getEuApprovedDate($format = 'd.m.Y')
	{ 
		if(self::formatDate($this->EuApprovedDate, $format) != date($format, 0))
		{ return self::formatDate($this->EuApprovedDate, $format); }
		else
		{ return ''; }
	}
	
	public function getUseBrand() 
	{ 
		if(self::getTypeId() == 4)
		{ return 0; }
		else
		{ return 1; }
	}
	
	
	public function setAdVehicleId($val) { $this->AdVehicleId=intval($val); }
	public function setMaintenanceDoc($val) { $this->MaintenanceDoc=intval($val); }
	public function setAirCondition($val) { $this->AirCondition=intval($val); }
	public function setAditionalHydra($val) { $this->AditionalHydra=intval($val); }
	public function setCeMarked($val) { $this->CeMarked=intval($val); }
	public function setConformityDeclaration($val) { $this->ConformityDeclaration=intval($val); }
	public function setAutoTrans($val) { $this->AutoTrans=intval($val); }
	public function setTrailerBreak($val) { $this->TrailerBreak=intval($val); }
	public function setLoadCapacityVolume($val) { $this->LoadCapacityVolume=intval($val); }
	public function setLoadCapacityWeight($val) { $this->LoadCapacityWeight=intval($val); }
	public function setEuApproved($val) { $this->EuApproved=intval($val); }
	public function setWheelbase($val) { $this->Wheelbase=intval($val); }
	public function setTailLift($val) { $this->TailLift=intval($val); }
	public function setInsideLength($val) { $this->InsideLength=intval($val); }
	public function setInsideWidth($val) { $this->InsideWidth=intval($val); }
	public function setClutchlessTurningGear($val) { $this->ClutchlessTurningGear=intval($val); }
	public function setSpeedGear($val) { $this->SpeedGear=intval($val); }
	public function setSpringCottage($val) { $this->SpringCottage=intval($val); }
	public function setSuspFrontAxle($val) { $this->SuspFrontAxle=intval($val); }
	
	function update()
	{
		if((self::getId() > 0) && (self::getDataChanged()))
		{
			global $user;
			if(($user->getId() == self::getUserId()) || ($user->getLevel() > 4) || (defined('RUN_IMPORT')))
			{
				self::updateAd();
				
				if(self::getAdVehicleId() > 0)
				{
					$sql  = 'UPDATE '.DB_PERFIX.'am_ads_vehicle SET ';
					$sql .= '`AdVehicleId`='.self::getId().', ';
					$sql .= '`MaintenanceDoc`='.self::getMaintenanceDoc().', ';
					$sql .= '`AirCondition`='.self::getAirCondition().', ';
					$sql .= '`AditionalHydra`='.self::getAditionalHydra().', ';
					$sql .= '`CeMarked`='.self::getCeMarked().', ';
					$sql .= '`ConformityDeclaration`='.self::getConformityDeclaration().', ';
					$sql .= '`YearReg`="'.self::getYearReg().'", ';
					$sql .= '`AutoTrans`='.self::getAutoTrans().', ';
					$sql .= '`TrailerBreak`='.self::getTrailerBreak().', ';
					$sql .= '`LoadCapacityVolume`='.self::getLoadCapacityVolume().', ';
					$sql .= '`LoadCapacityWeight`='.self::getLoadCapacityWeight().', ';
					$sql .= '`RegistrationNo`="'.self::formatText(self::getRegistrationNo()).'", ';
					$sql .= '`EuApproved`='.self::getEuApproved().', ';
					$sql .= '`EuApprovedDate`="'.self::getEuApprovedDate().'", ';
					$sql .= '`CabinType`="'.self::formatText(self::getCabinType()).'", ';
					$sql .= '`SuspensionFront`="'.self::formatText(self::getSuspensionFront()).'", ';
					$sql .= '`SuspensionRear`="'.self::formatText(self::getSuspensionRear()).'", ';
					$sql .= '`Wheelbase`='.self::getWheelbase().', ';
					$sql .= '`ShaftType`="'.self::formatText(self::getShaftType()).'", ';
					$sql .= '`TailLift`='.self::getTailLift().', ';
					$sql .= '`InsideLength`='.self::getInsideLength().', ';
					$sql .= '`InsideWidth`='.self::getInsideWidth().', ';
					$sql .= '`ClutchlessTurningGear`='.self::getClutchlessTurningGear().', ';
					$sql .= '`SpeedGear`='.self::getSpeedGear().', ';
					$sql .= '`SpringCottage`='.self::getSpringCottage().', ';
					$sql .= '`SuspFrontAxle`='.self::getSuspFrontAxle().', ';
					$sql .= '`IsTracked`='.self::getIsTracked().' ';
					$sql .= ' WHERE AdVehicleId='.self::getId().' LIMIT 1;';
					mysql_query($sql);
				}
				else
				{
					$insert  = '`AdVehicleId`';
					$values  = self::getId();
					$insert .= ', `MaintenanceDoc`';
					$values .= ', '.self::getMaintenanceDoc();
					$insert .= ', `AirCondition`';
					$values .= ', '.self::getAirCondition();
					$insert .= ', `AditionalHydra`';
					$values .= ', '.self::getAditionalHydra();
					$insert .= ', `CeMarked`';
					$values .= ', '.self::getCeMarked();
					$insert .= ', `ConformityDeclaration`';
					$values .= ', '.self::getConformityDeclaration();
					$insert .= ', `YearReg`';
					$values .= ', "'.self::getYearReg().'"';
					$insert .= ', `AutoTrans`';
					$values .= ', '.self::getAutoTrans();
					$insert .= ', `TrailerBreak`';
					$values .= ', '.self::getTrailerBreak();
					$insert .= ', `LoadCapacityVolume`';
					$values .= ', '.self::getLoadCapacityVolume();
					$insert .= ', `LoadCapacityWeight`';
					$values .= ', '.self::getLoadCapacityWeight();
					$insert .= ', `RegistrationNo`';
					$values .= ', "'.self::formatText(self::getRegistrationNo()).'"';
					$insert .= ', `EuApproved`';
					$values .= ', '.self::getEuApproved();
					$insert .= ', `EuApprovedDate`';
					$values .= ', "'.self::getEuApprovedDate().'"';
					$insert .= ', `CabinType`';
					$values .= ', "'.self::formatText(self::getCabinType()).'"';
					$insert .= ', `SuspensionFront`';
					$values .= ', "'.self::formatText(self::getSuspensionFront()).'"';
					$insert .= ', `SuspensionRear`';
					$values .= ', "'.self::formatText(self::getSuspensionRear()).'"';
					$insert .= ', `Wheelbase`';
					$values .= ', '.self::getWheelbase();
					$insert .= ', `ShaftType`';
					$values .= ', "'.self::formatText(self::getShaftType()).'"';
					$insert .= ', `TailLift`';
					$values .= ', '.self::getTailLift();
					$insert .= ', `InsideLength`';
					$values .= ', '.self::getInsideLength();
					$insert .= ', `InsideWidth`';
					$values .= ', '.self::getInsideWidth();
					$insert .= ', `ClutchlessTurningGear`';
					$values .= ', '.self::getClutchlessTurningGear();
					$insert .= ', `SpeedGear`';
					$values .= ', '.self::getSpeedGear();
					$insert .= ', `SpringCottage`';
					$values .= ', '.self::getSpringCottage();
					$insert .= ', `SuspFrontAxle`';
					$values .= ', '.self::getSuspFrontAxle();
					$insert .= ', `IsTracked`';
					$values .= ', '.self::getIsTracked().' ';
					
					$sql  = 'INSERT INTO '.DB_PERFIX.'am_ads_vehicle ('.$insert.')'; 
					$sql .= 'VALUES ('.$values.');';
					$result = mysql_query($sql);
				}
			}
			//if(($user->getId() == 1) || (defined('RUN_IMPORT')))
			//{ echo $sql.'<br /><hr />'; }
		}
	}
}
?>